package com.example.night.service;

import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;

@Service
public class TimeService {
    public static String[] getStartAndEndOfYesterday() {
        LocalDateTime now = LocalDateTime.now().minusDays(1); // 获取前一天
        DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");

        // 获取前一天的开始时间
        String startOfDay = now.toLocalDate().atStartOfDay().format(formatter);
        // 获取前一天的结束时间
        String endOfDay = now.toLocalDate().atTime(23, 59, 59).format(formatter);

        return new String[] { startOfDay, endOfDay };
    }

    public static String[] getStartAndEndOfToday() {
        LocalDateTime now = LocalDateTime.now();
        DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");

        // 获取前一天的开始时间
        String startOfDay = now.toLocalDate().atStartOfDay().format(formatter);
        // 获取前一天的结束时间
        String endOfDay = now.toLocalDate().atTime(23, 59, 59).format(formatter);

        return new String[] { startOfDay, endOfDay };
    }
}
